<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Entity_Tag extends Core_Db_Entity {

	public function __construct() {
		parent::__construct(App::db());
		$this->setBaseTable('tag');
	}
	
	public function loadByName($name) {
		$query = $this->_conn->get_where( $this->_table, array('name' => $name) );
		$this->addData($query->first_row(0));
		return $this;
	}
	
	protected function _beforeDelete() {
		// delete record in post_tag
		$this->_conn->query("DELETE FROM post_tag WHERE tag_id={$this->getId()}");
		return $this;
	}
	
	public function getUrl() {
		return App::url('*/*', array('_query' => array('tags' => $this->getId())));
	}
}